var boo=true;
var boo1=true;
layui.use([ 'laydate' ], function() {
    var laydate = layui.laydate;
    var $ = layui.jquery;
    videoCount();
    videoLook();
    videoCollect();
    videoLike();

    courseStatus();
    productSate();
    today();
    yesterday();
    month();
    count();
    courseMonth();
    successfulApplication();
    courseLastMonth();
    lastApplication();
    seTab();//课程待审核个数
    conToAudit(2);//统计待审核商品数量
    if(boo==false&&boo1==false){
        var i="<li class='aff_li_item' id='aff_apply'>"
            +"<p class='dis_thing'><a href='' class='dis_a'>未有通知</a></p>"
            +"<>"
        $(".div_aff_ul").append(i)
    }

    var a = parse("user");
    laydate.render({
        elem: '#div5_date'
        , type: 'date'
        , range: true
    });
    //系统首页——上传视频总数
    function videoCount() {
        $.ajax({
            url: "/teacherSystem/selVideoCount",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#videoCount").text(data.data);
                } else {
                    $("#videoCount").text(0);
                }
            }
        });
    }
    //系统首页——上传的视频浏览数
    function videoLook() {
        $.ajax({
            url: "/teacherSystem/selVideoLook",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#videoLook").text(data.data);
                } else {
                    $("#videoLook").text(0);
                }
            }
        });
    }
    //系统首页——收藏量
    function videoCollect() {
        $.ajax({
            url: "/teacherSystem/selVideoCollect",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#videoCollect").text(data.data);
                } else {
                    $("#videoCollect").text(0);
                }
            }
        });
    }
    //系统首页——点赞量
    function videoLike() {
        $.ajax({
            url: "/teacherSystem/selVideoLike",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#videoLike").text(data.data);
                } else {
                    $("#videoLike").text(0);
                }
            }
        });
    }



    //统计待审核商品数量
    function conToAudit(productSate){
        $.post("/SyOperationController/getStatisticalAuditStatus",{"productSate":productSate},function (data) {
            if (data.data!=0&&data.data!=null) {
                var i= "<li class='aff_li_item' id='aff_apply'>"
                    +"<p class='dis_thing'><a onclick=\"xadmin.add_tab('商品待审核信息','/operation/PendingProducts.html',true)\" class='dis_a'>商品待审核信息</a></p>"
                    +"<p class='dis_num'>(<span class='dis_num_span' id='courseCstatus1'>"+data.data+"</span>)</p>"
                    +"</li>"
                $(".div_aff_ul").append(i)
            } else {
                boo=false;
                return boo;
            }

        });
    }


    //系统首页——课程待审核信息
    function seTab(){
        $.ajax({
            url:"/SyteacherSelController/Secstatus",
            type:"post",
            dataType:"json",
            data:[],
            success:function(data){
                if (data.data!=0&&data.data!=null) {
                    var i= "<li class='aff_li_item' id='aff_apply'>"
                        +"<p class='dis_thing'><a onclick=\"xadmin.add_tab('课程待审核信息','/public/CourseCheck.html',true)\" class='dis_a'>课程待审核信息</a></p>"
                        +"<p class='dis_num'>(<span class='dis_num_span' id='courseCstatus1'>"+data.data+"</span>)</p>"
                        +"</li>"
                    $(".div_aff_ul").append(i)
                } else {
                    boo1=false;
                    return boo1;
                }
            }
        });
    }



    //商品总览——课程数量（已上架）
    function courseStatus() {
        $.ajax({
            url: "/teacherSystem/selCourseStatus",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#courseStatus").text(data.data);
                } else {
                    $("#courseStatus").text(0);
                }
            }
        });
    }
    //首页——商品总览——商品数量（已上架）
    function productSate() {
        $.ajax({
            url: "/teacherSystem/selProductSate",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#productSate").text(data.data);
                } else {
                    $("#productSate").text(0);
                }
            }
        });
    }
    //用户总览——今日新增用户总览量
    function today() {
        $.ajax({
            url: "/teacherSystem/selUserOverviewToday",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#today").text(data.data);
                } else {
                    $("#today").text(0);
                }
            }
        });
    }
    //用户总览——昨日新增用户总览量
    function yesterday() {
        $.ajax({
            url: "/teacherSystem/selUserOverviewYesterday",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#yesterday").text(data.data);
                } else {
                    $("#yesterday").text(0);
                }
            }
        });
    }
    //用户总览——本月新增用户总览量
    function month() {
        $.ajax({
            url: "/teacherSystem/selUserOverviewMonth",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#month").text("" + data.data + "");
                } else {
                    $("#month").text(0);
                }
            }
        });
    }
    //用户总览——全部用户
    function count() {
        $.ajax({
            url: "/teacherSystem/selUserOverviewCount",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#count").text("" + data.data + "");
                } else {
                    $("#count").text(0);
                }
            }
        });
    }
    var courseLastMonth1=0;
    var lastApplication1=0;
    //本月新增课程总数
    function courseMonth() {
        $.ajax({
            url: "/teacherSystem/selCourseMonth",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#courseMonth").text("" + data.data + "");
                    courseLastMonth1 = data.data;
                } else {
                    $("#courseMonth").text(0);
                }
            }
        });
    }
    //上月新增课程总数
    function courseLastMonth() {
        $.ajax({
            url: "/teacherSystem/selCourseLastMonth",
            type: "get",
            dataType: "json",
            success: function (data) {
                if (data.data) {
                    var cm = courseLastMonth1 - data.data;
                    $("#courseLastMonth").html(cm / 100 + '%');
                } else {
                    $("#courseLastMonth").html(0);
                }
            }
        })
    }
    //本月申请成功
    function successfulApplication() {
        $.ajax({
            url: "/teacherSystem/selSuccessfulApplication",
            type: "get",
            dataType: "json",
            data: {data: "data"},
            success: function (data) {
                if (data.data) {
                    $("#successfulApplication").text(data.data);
                    lastApplication1 = data.data;
                } else {
                    $("#successfulApplication").text(0);
                }
            }
        })
    }

    $("#button_refresh").on('click',function(){
        window.location.href = window.location.href;
    });
    //上月申请成功
    function lastApplication() {
        $.ajax({
            url: "/teacherSystem/selLastApplication",
            type: "get",
            dataType: "json",
            success: function (data) {
                if (data.data==undefined) {
                    var la = lastApplication1 - data.data;
                    $("#lastApplication").html(la / 100 + '%');
                } else {
                    $("#lastApplication").html(0);
                }
            }
        })
    }
    var d;
    $.ajax({
        url: '/teacherSystem/selCurriculumCount',
        type: "post",
        dataType: "json",
        data: {"name": "FeedbackStatistics"},
        success: function (data) {
            selOperationlog("查询反馈统计")
            d = data.data;
            ch(d.day, d.dayData)
        }
    });
    //本月
    $(".active3").on('click', function () {
        $("#tip2").removeAttr("class", "xiaxian ");
        $("#tip1").removeAttr("class", "xiaxian");
        $("#tip3").attr("class", "tip3 xiaxian");
        ch(d.month, d.monthData)
    });
    //本天
    $(".active1").on('click', function () {
        $("#tip2").removeAttr("class", "xiaxian ");
        $("#tip3").removeAttr("class", "xiaxian");
        $("#tip1").attr("class", "tip1 xiaxian");
        ch(d.day, d.dayData)
    });
    //本周;
    $(".active2").on('click', function () {
        $("#tip1").removeAttr("class", "xiaxian ");
        $("#tip3").removeAttr("class", "xiaxian");
        $("#tip2").attr("class", "tip2 xiaxian");
        ch(d.week, d.weekData)
    });
    var chart = echarts.init($('#querycnt').get(0));
    var chartOption = {
        legend: {
            data: ["课程量"],
            bottom: 20
        },
        grid: {
            top: 10,
            height: 170
        },
        xAxis: {
            data: [],
            axisLabel: {rotate: 0, interval: 0},
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            }
        },
        yAxis: [{
            scale: true,
            name: "",
            axisLine: {
                show: false
            },
            axisTick: {
                show: false
            }
        }],
        tooltip: {},
        series: [{
            name: '课程量',
            type: 'line',
            smooth: true,
            data: [],
            itemStyle: {
                normal: {
                    color: '#5aa7fe'
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0, color: '#5aa7fe' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#bcdbff' // 100% 处的颜色
                    }], false)
                }
            }
        }
        ]//series
    };//option
    chart.setOption(chartOption);
    chart.showLoading();
    chart.hideLoading();

    function ch(data, date) {
        chart.setOption({
            xAxis: {
                data: date
            },
            series: [{
                name: '课程量',
                data: data
            }]
        });
    }
});
